# 14.使用模板
import uvicorn
from fastapi import FastAPI
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates

app = FastAPI()
templates = Jinja2Templates(directory="templates")


# 装饰器
@app.get("/books/{book_name}", response_class=HTMLResponse)
def get_book_by_id(book_name, request: Request):

    s1 = "Long long ago, there's a girl named betty! She was 5 years old."
    s2 = "  " + s1 + "  "
    s3 = "<p style='color: blue;'>" + s1 + "</p>"


    return templates.TemplateResponse(name="hello.html",
                                      context={"request": request,
                                               "book_name": book_name,
                                               'message': (s1,s2,s3)})



if __name__ == "__main__":
    uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
